import {post, get, dele, put} from '@/utils/serviceHelper.js';

const RISK_REASON_LIST_LIST = "RISK_REASON_LIST_LIST";
const state = {
    riskReasonList: [],
    riskReasonPage: {page: 0, rows: 10, count: 0}
}

const getters = {
    riskReasonList(state) {
        return state.riskReasonList;
    },
    riskReasonPage(state) {
        return state.riskReasonPage;
    }
}

const actions = {
    getRiskReasonList({commit, state}, param) {
        get('/manage/reason', {...state.riskReasonPage, ...param}).then((res) => {
            if (res.code == 0) {
                commit(RISK_REASON_LIST_LIST, res);
            }
        })
    },
    getRiskReasonInfo({commit, state}, param) {
        return new Promise((resolve, reject) => {
            get('/manage/reason/riskReason', param).then((res) => {
                if (res.code == 0) {
                    resolve(res.rs);
                } else {
                    reject(res.messages);
                }
            })
        });
    },
    addRiskReason({commit, state}, param) {
        return new Promise((resolve, reject) => {
            post('/manage/reason', param).then((res) => {
                if (res.code == 0) {
                    resolve(res.rs);
                } else {
                    reject(res.messages);
                }
            })
        });
    },
    editRiskReason({commit, state}, param) {
        return new Promise((resolve, reject) => {
            put('/manage/reason', param).then((res) => {
                if (res.code == 0) {
                    resolve(res.rs);
                } else {
                    reject(res.messages);
                }
            })
        });
    },
    deleteRiskReason({commit, state}, param) {
        return new Promise((resolve, reject) => {
            dele('/manage/reason/' + param.id, param).then((res) => {
                if (res.code == 0) {
                    resolve(res.rs);
                } else {
                    reject(res.messages);
                }
            })
        });
    }
}
const mutations = {
    [RISK_REASON_LIST_LIST](state, data) {
        state.riskReasonList = data.rs;
        state.riskReasonPage.count = data.count;
    }
}

export default {
    state,
    getters,
    actions,
    mutations
}
